#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Spoor Enumeration Tool
#  
#  Copyright 2013 David Martinez <dmartinez7500@gmail.com>
#  
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#  
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#  
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
#  MA 02110-1301, USA.
#  
#  
import argparse
from shodan import WebAPI

SHODAN_API_KEY = "GM5SvHv2uHxEjSN0NlA7ZJl77SI2Ob7y"
api = WebAPI(SHODAN_API_KEY)


# Parse Arguments##################################################
parser = argparse.ArgumentParser()
parser.add_argument("-s", "--shodan", help="Use the SHODAN API to search.", nargs='*')
#parser.add_argument("-s", "--shodan-host", help="Use the SHODAN API to search by specific host name.", nargs='*')
parser.add_argument("-w", "--whois", help="Run a WHOIS search by IP or Domain", nargs='*')
parser.add_argument("-n", "--nslookup", help="Perform DNS queries", nargs='*')
parser.add_argument("-o", help="Specify an output file to write the results to", nargs='*')
args = parser.parse_args()
###################################################################

def main():
		
	return 0

def shodan_basic_search():
	shodan_query= ' '.join(args.shodan)
	
	# Wrap the request in a try/ except block to catch errors
	try:
		# Search Shodan
		results = api.search(shodan_query)

		# Show the results
		print 'Results found: %s' % results['total']
		raw_input()
		for result in results['matches']:
			print 'IP: %s' % result['ip']
			print result['data']
			print ''
	except Exception, e:
		print 'Error: %s' % e

def whois():
	print "WHOIS Lookup"
	
def nslookup():
	print "NSLOOKUP"
	
print args 

raw_input()
	
if args.shodan:
	print "SHODAN Search Query: ", ' '.join(args.shodan)
	shodan_basic_search()
elif args.whois:
	print args.whois
	whois()
elif args.nslookup:
	print args.nslookup
	nslookup()
	
if __name__ == '__main__':
    main()
